<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of genReporte
 *
 * @author mini
 */
class Evaluaciones extends CI_Controller {

    public function __construct() {
        parent::__construct();
        global $admin, $data;
        #Cargamos datos del administrador
        $admin = $this->session->userdata('admin');
        $this->verificacion_acceso($admin);
        $admin['place'] = 'evaluaciones';
        $this->output->enable_profiler(FALSE);
    }

    public function index() {
        global $admin, $data;

        $data['listTest'] = $this->cc_model_b->getDataMaterialXTest();
        
        $this->load->view('template/header', $admin);
        $this->load->view('template/open_content_container');
        $this->load->view('menu/menu_admin', $data);
        $this->load->view('evaluaciones/content');
        $this->load->view('template/close_content_container');
        $this->load->view('template/footer');
    }
    
    public function data(){
        
        global $admin, $data;
        
        $data['empresa'] = $this->cc_model_a->cEmpresas();
        $data['mensaje'] = "";
        
        $this->load->view('template/header', $admin);
        $this->load->view('template/open_content_container');
        $this->load->view('menu/menu_admin', $data);
        $this->load->view('evaluaciones/captura');
        $this->load->view('template/close_content_container');
        $this->load->view('template/footer');
    }
    
    public function addquestion(){
        
        $this->session->set_userdata('nquestion',1);
        
        $this->load->view('template/header', $admin);
        $this->load->view('template/open_content_container');
        $this->load->view('menu/menu_admin', $data);
        $this->load->view('evaluaciones/addquestions');
        $this->load->view('template/close_content_container');
        $this->load->view('template/footer');
    }
    
    public function saveData(){
        global $admin,$data;
        
        $this->setRulesSaveData();
        $e_empresa_id = $this->security->xss_clean($this->input->post('e_empresa_id'));
        $d_division_id = $this->security->xss_clean($this->input->post('d_division_id'));
        $m_modulo_id = $this->security->xss_clean($this->input->post('m_modulo_id'));
        $sm_sub_modulo_id = $this->security->xss_clean($this->input->post('sm_sub_modulo_id'));
        $m_material_id = $this->security->xss_clean($this->input->post('m_material_id'));
        
        $this->session->set_userdata('q_m_material_id',$m_material_id);
        $this->session->set_userdata('nquestion',1);
        
        $this->load->view('template/header', $admin);
        $this->load->view('template/open_content_container');
        $this->load->view('menu/menu_admin', $data);
        $this->load->view('evaluaciones/addquestions');
        $this->load->view('template/close_content_container');
        $this->load->view('template/footer');
    }
    
    public function setRulesSaveData(){
        $this->form_validation->set_rules('e_empresa_id','Empresa','required|trim|xss_clean|max_length[5]');
        $this->form_validation->set_rules('d_division_id','Division','required|trim|xss_clean|max_length[5]');
        $this->form_validation->set_rules('m_modulo_id','Módulo','required|trim|xss_clean|max_length[5]');
        $this->form_validation->set_rules('sm_sub_modulo_id','Sub-Modulo','required|trim|xss_clean|max_length[5]');        
        $this->form_validation->set_rules('m_material_id','Material','required|trim|xss_clean|max_length[5]');
        
        if (!$this->form_validation->run()) {
            $errorMsj = '   <div class="alert alert-error" style="margin-top: 16px;">
                            <button type="button" class="close" data-dismiss="alert">×</button>
                            <strong>Error al validar el formulario </strong> </div>';
            $this->session->set_userdata('mensaje', $errorMsj);
            redirect('evaluaciones/captura');
        }
        
    }
    
    /**
     * Funcion que se encarga de verificar que 
     * se logueara antes
     */
    public function verificacion_acceso($admin) {
        if ($admin['ta_tipo_administrador_id'] != 1) {
            redirect('home');
        }
    }



}